package boun.swe.bob.service;

import com.google.common.collect.Maps;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * This controller is used for my wall page actions
 */
public class MyWallController extends BaseController {

    /**
     * Shows the page
     *
     * @param httpServletRequest http request
     * @param httpServletResponse http response
     * @return page
     */
    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView showPage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        Map<String, Object> myModel = Maps.newHashMap();
        String wantedUserId = httpServletRequest.getParameter("wantedUserId");
        if(null == wantedUserId) {

            myModel.put("user", userDao.findByPrimaryKey(getLoggedInUser(httpServletRequest).getUserId()));
            myModel.put("himself",  true  );
            
        } else {
            myModel.put("user", userDao.findByPrimaryKey(Integer.parseInt(wantedUserId)));
            //giris yapan user ile wanted user ayni ise himself diger durumda degil
            myModel.put("himself", getLoggedInUser(httpServletRequest).getUserId() ==Integer.parseInt(wantedUserId) ? true : false );
        }
        return new ModelAndView("myWall", "model", myModel);
    }

}
